#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main()
{
    int n;
    cin >> n;
    int a = 0 , b = 1 , c = 1;
    while(n > c)
    {
        a = b;
        b = c;
        c = a + b;
    }
    cout << min(c - n , n - b) << endl;
    return 0;
}